package com.ljkj.blockpay.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import androidx.annotation.Nullable;
import androidx.constraintlayout.utils.widget.ImageFilterButton;

import com.bumptech.glide.Glide;
import com.kongzue.baseokhttp.util.JsonList;
import com.kongzue.baseokhttp.util.JsonMap;
import com.ljkj.blockpay.R;
import com.ljkj.blockpay.basedata.BaseActivity;
import com.ljkj.blockpay.databinding.ActivitySfzactivityBinding;
import com.ljkj.blockpay.presenter.SFZPresenter;
import com.ljkj.blockpay.presenter.inter.SFZinterface;
import com.ljkj.blockpay.util.ToggleToActivity;
import com.ljkj.blockpay.widget.ClickListener;
import com.luck.picture.lib.tools.ToastUtils;

/**
 * tagPage
 *      1,绑定手机
 *      2,邮箱页面
 *      3,安全验证页面
 *
 */
public class SFZActivity extends BaseActivity<ActivitySfzactivityBinding, SFZPresenter> implements SFZinterface.SFZinterfaceView , ClickListener {

    private String country;
    private String etinput;
    private String etcode;
    @Override
    public int initContentView() {
        return R.layout.activity_sfzactivity;
    }

    @Override
    protected SFZPresenter createPresenter() {
        return new SFZPresenter(this,this);
    }

    @Override
    protected void init(Bundle savedInstanceState) {
        binding.tvTitle.setLeftBackFinish(this);
    }

    @Override
    protected void initData() {
        super.initData();
        getPresenter().tagPage =  getIntent().getIntExtra("tagPage",1);
        binding.textTitle.setText(getPresenter().getTitle());
        binding.textTipe.setText(getPresenter().getNotice());
        switch (getPresenter().tagPage){
            case 1:
                binding.rlPhone.setVisibility(View.VISIBLE);
                binding.rlVerify.setVisibility(View.VISIBLE);
                binding.etInput.setHint(getResources().getString(R.string.phone));

                break;
            case 2:
                binding.ivCountryicon.setVisibility(View.GONE);
                binding.tvCountry.setVisibility(View.GONE);
                break;
            case 3:
                binding.ivCountryicon.setVisibility(View.GONE);
                binding.tvCountry.setVisibility(View.GONE);
                break;
            default:
                break;
        }

        country = binding.tvCountry.getText().toString();
        etinput = binding.etInput.getText().toString();
        etcode = binding.etVericode.getText().toString();
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){

            case R.id.iv_countryicon:
            case R.id.tv_country:
                ToggleToActivity.toSelectActivity(this,10);
                break;
            case R.id.tv_sendverification:
                switch (getPresenter().tagPage){
                    case 1:
                        getPresenter().verifycode(country,103);
                        break;
                    case  2:
                        getPresenter().verifycode(etinput,103);
                        break;
                    case 3:
                        //此处存疑，设置或修改交易密码
                        getPresenter().verifycode(etinput,105);
                        break;
                }

                break;
            case R.id.btn_bindchange:
                switch (getPresenter().tagPage){
                    case 1:

                        if (country.isEmpty()){
                            ToastUtils.s(this,"国家地区不能为空");
                        } else if (etinput.isEmpty()){
                            ToastUtils.s(this,"手机号不能为空");
                        } else if (etcode.isEmpty()){
                            ToastUtils.s(this,"验证码不能为空");
                        } else {

                        }
                        break;
                    case 2:

                        break;
                    case 3:

                        break;
                    default:
                        break;
                }

                break;
        }
    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (data != null){
            if (data.getExtras() != null){
                Bundle bundle = data.getExtras();
                JsonMap jsonMap = JsonMap.parse(bundle.getString("jsonMap"));
                switch (requestCode){
                    case 10:
                        String countryCode = jsonMap.getString("countryCode");
                        String countryIcon = jsonMap.getString("countryIcon");
                        Glide.with(this).load(countryIcon).into(binding.ivCountryicon);
                        binding.tvCountry.setText(countryCode);
                        break;
                }
            }
           
        }
    }

    /**
     * 绑定成功
     * @param jsonMap
     */
    @Override
    public void bindSuccess(JsonMap jsonMap) {

    }

    /**
     * 验证码发送
     * @param jsonMap
     */
    @Override
    public void verifySucess(JsonMap jsonMap) {

    }
    


}